package concurrent.year2021;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadStateTest2 {
    public static void main(String[] args) throws InterruptedException {
        ThreadStateTest2 o = new ThreadStateTest2();
        new Thread(() -> {
            try {
                o.syncFun();
                System.out.println("thread end syncFun");
                TimeUnit.DAYS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "haha").start();
        TimeUnit.SECONDS.sleep(5);
        o.syncFun(); // monitor BLOCKED
        System.out.println("end");
    }

    int i = 0;
    public synchronized void syncFun() throws InterruptedException {
        System.out.println(i++);
        this.wait();

    }
}
